<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	response.setHeader("cache-control","public");
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html><title>在线考试系统</title>
<!-- 创建题库 -->
<head>
	<meta charset="utf-8">
	<meta http-equiv="Content-Type" content="multipart/form-data;charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="renderer" content="webkit">
	<title>在线考试系统</title>
	<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/font/font-awesome.min.css">
	<!--[if IE 7]><link rel="stylesheet" href="<%=path%>/static/css/font/font-awesome-ie7.min.css"><![endif]-->
	<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/common.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/examMng/core.css">
	<link rel="stylesheet" href="<%=path%>/static/css/examMng/examMng.css" />
	<!--bootstrap基础引用 start-->
	<script type="text/javascript" src="<%=path%>/static/jstreeview/bootstrap/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="<%=path%>/static/js/bootstrap.min.js"></script>
	<!--bootstrap基础引用 end-->
	<!--bootstrap-dialog start-->
	<link rel="stylesheet" type="text/css" href="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.css">
	<script type="text/javascript" src="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.js"></script>
	<!--bootstrap-dialog end-->
	<!--[if !IE]> -->
	<script type="text/javascript">
		window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
	</script>
	<!-- <![endif]-->
	<script type="text/javascript">
		window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-1.9.1.min.js'>"+"<"+"/script>");
	</script>
	<script type="text/javascript" src="<%=path%>/static/js/respond.js"></script>
	<script type="text/javascript" src="<%=path%>/static/js/jquery.selectlist.js" ></script>
</head>
<body>
<jsp:include page="../head.jsp" flush="true"/>
<!--body begin-->
<div class="main-container" >
	<div class="container body-box" >
		<div class="info-add-box" style="background: #4c4ca6;">题库信息录入：</div>
		<div class="content-box">
			<div class="overflow">
				<form enctype="multipart/form-data" id="depository">
					<div class="col-lg-10 col-md-10" style="padding:0">
						<div class="input-group input-group-lg tk-title">
							<input name="id" value="${depo.id }" type="hidden">
							<span class="input-group-addon">题库名称</span>
							<input id="title" maxlength="30" name="title" type="text" class="form-control" value="${depo.name }" placeholder="请输入题库名称" aria-describedby="sizing-addon1">
						</div>
						<div class="input-group input-group-lg tk-title">
							<span class="input-group-addon">考试类型</span>
							<div class="btn-group btn-group-lg" role="group">
								<select id="type" name="type"  class="form-control">
									<option value="0">请选择</option>
									<c:forEach items="${typeList }" var="types">
										<option id="${depo.type_id }" value="${types.id}"  <c:if test="${types.id == depo.type_id}"> selected </c:if>>${types.name }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="input-group input-group-lg tk-title tk-introduction">
							<span class="input-group-addon" id="sizing-addon1">题库简介</span>
							<textarea id="description" type="text" name="description" class="form-control" style="height:120px;" placeholder="请输入题库名称" aria-describedby="sizing-addon1" maxlength="200">${depo.description }</textarea>
						</div>
					</div>
					<div class="col-lg-2 col-md-2" style="padding-right:0">
						<a id="imgArea" href="javascript:file_upload.click()">
							<c:choose>
								<c:when test="${label eq 'edit'}">
									<div class="info-add-photo"><img id="${label}pict" src="<%=basePath %>${depo.picture }"></div>
								</c:when>
								<c:otherwise>
									<div class="info-add-photo"><img id="${label}pict" src="<%=path %>/static/images/examMng/photos.png"></div>
								</c:otherwise>
							</c:choose>
							<div class="info-add-text text-center">
								<p>点击上传题库封面图片</p>
								<input id="file_upload" name="file_upload" class="info-choose" type="file" style="display: none;">
							</div>
						</a>
					</div>
				</form>
			</div>
			<div class="line-bottom"></div>
			<div class="anniu-group" style="margin: 20px auto 20px auto;">
				<button class="btn btn-danger" onclick="javascript:history.back(-1);" role="button">取消</button>
				<c:choose>
					<c:when test="${label eq 'edit'}">
						<button class="btn btn-success" onclick="updateInfo();" role="button" style="background: #4c4ca6">修改题库</button>
					</c:when>
					<c:otherwise>
						<button class="btn btn-success" onclick="submitInfo();" role="button"  style="background: #4c4ca6">创建题库</button>
					</c:otherwise>
				</c:choose>
			</div>
		</div>
	</div>
</div>
<!--body end-->
<!--不能为空-->
<div id="baocun" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="width: 300px">
		<div class="modal-content">
			<!--不能为空header开始-->
			<div class="modal-header">
				<div class="table-header border-top-radius">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					&nbsp;
				</div>
			</div>
			<!--删除header结束-->
			<!--删除body开始-->
			<div class="modal-body">
				<div class="text-center">
					不能为空
				</div>
			</div>
			<!--删除body结束-->
			<!--删除footer开始-->
			<div class="modal-footer">
				<button class="btn btn-sm btn-success" data-dismiss="modal" id="sure-close">
					<i class="icon-ok"></i>确定
				</button>
				<button class="btn btn-sm btn-danger" data-dismiss="modal">
					<i class="icon-remove"></i>取消
				</button>
			</div>
			<!--删除footer结束-->
		</div>
	</div>
</div>
<!--不能为空-->
<script type="text/javascript">
	var nums = 0;
	$(function() {
		// $('#topMain').children().eq(4).addClass('active'); // 追加样式;

		//试卷管理
		if (${role eq 'master'}) {
			$('#topMain').children().eq(0).addClass('active'); // 追加样式;
			$('#topMain').children().eq(0).children().attr('href', '#');
		} else if (${role eq 'trainee'}) {
			$('#topMain').children().eq(0).addClass('active'); // 追加样式;
			$('#topMain').children().eq(0).children().attr('href', '#');
		} else {
			$('#topMain').children().eq(3).addClass('active'); // 追加样式;
			// $('#topMain').children().eq(3).children().attr('href', '#');
		}

		$("#itemDate").selectlist({
			zIndex: 10,
			height: 60,
			onChange: null
		});
		$(document).ready(function(){
			nums = $(".main-container .info-add").length;
			footer_position();
			//当浏览器窗口大小改变时，设置显示内容的高度
			$(window).resize(function(){
				footer_position();
			});
		});
		//图片回显
		$(document).ready(function(){
			$("#imgArea").click(function(){
				var $input = $("#file_upload");
				$input.on("change" , function(){
					//3、回显
					var files = this.files;
					var fr = new FileReader();
					fr.onload = function(e){
						$("#${label}pict").attr('src',this.result);
						//$("#${label}pict").src = this.result;
					}
					fr.readAsDataURL(files[0]);//读取文件
				})
			})
		});
		function footer_position(){
			var winHeight = $(window).height();
			var myHeight = winHeight-60-82-20;
			if($(".main-container").height() <= myHeight){
				$(".kw-footer").css("position","fixed");
				$(".kw-footer").css("bottom","0");
				$(".main-container").css("min-height",myHeight+"px");
			}else{
				$(".kw-footer").css("position","initial");
			}
		}
	});
	function submitInfo(){
		var formElement = $("#depository")[0];
		var formData = new FormData(formElement);
		var title = formData.get("title");
		if(title == "" || title == null || title == undefined){ // "",null,undefined
			BootstrapDialog.confirm({
				title : '提示',
				message : '题库名称不能为空',
				size : BootstrapDialog.SIZE_SMALL,
				type : BootstrapDialog.TYPE_DEFAULT,
				closable : true,
				btnCancelLabel : '取消',
				btnOKLabel : '确定'
			});

			return;
		}
		var type = formData.get("type");
		if(type==0){ // "",null,undefined
			BootstrapDialog.confirm({
				title : '提示',
				message : '请选择考试大类',
				size : BootstrapDialog.SIZE_SMALL,
				type : BootstrapDialog.TYPE_DEFAULT,
				closable : true,
				btnCancelLabel : '取消',
				btnOKLabel : '确定'
			});
			return;
		}
		$.ajax({
			type:"POST",
			url:"<%=basePath %>depository/addDepository" ,
			data:formData,
			async: false,
			cache: false,
			contentType: false,
			processData: false,
			success:function(data){
				if(data.status==1){
					BootstrapDialog.confirm({
						title : '提示',
						message : data.msg,
						size : BootstrapDialog.SIZE_SMALL,
						type : BootstrapDialog.TYPE_DEFAULT,
						closable : true,
						btnCancelLabel : '取消',
						btnOKLabel : '确定',
						callback:function(result){
							window.location.href="<%=path%>/depository/toPage";
						}
					});
				}else{
					BootstrapDialog.confirm({
						title : '提示',
						message : data.msg,
						size : BootstrapDialog.SIZE_SMALL,
						type : BootstrapDialog.TYPE_DEFAULT,
						closable : true,
						btnCancelLabel : '取消',
						btnOKLabel : '确定'
					});
				}
			}
		})
	}

	function updateInfo(){
		var formElement = $("#depository")[0];
		var formData = new FormData(formElement);
		var title = formData.get("title");
		var id = formData.get("id");
		if(title == "" || title == null || title == undefined){ // "",null,undefined
			BootstrapDialog.confirm({
				title : '提示',
				message : '题库名称不能为空',
				size : BootstrapDialog.SIZE_SMALL,
				type : BootstrapDialog.TYPE_DEFAULT,
				closable : true,
				btnCancelLabel : '取消',
				btnOKLabel : '确定'
			});
			return;
		}
		var type = formData.get("type");
		if(type==0){ // "",null,undefined
			BootstrapDialog.confirm({
				title : '提示',
				message : '请选择考试大类',
				size : BootstrapDialog.SIZE_SMALL,
				type : BootstrapDialog.TYPE_DEFAULT,
				closable : true,
				btnCancelLabel : '取消',
				btnOKLabel : '确定'
			});
			return;
		}
		$.ajax({
			type:"POST",
			url:"<%=basePath %>depository/updateDepo" ,
			data:formData,
			async: false,
			cache: false,
			contentType: false,
			processData: false,
			success:function(data){
				if(data.status==1){
					$("#${label}pict").attr("src","<%=basePath %>"+data.picPath);
					BootstrapDialog.confirm({
						title : '提示',
						message : data.msg,
						size : BootstrapDialog.SIZE_SMALL,
						type : BootstrapDialog.TYPE_DEFAULT,
						closable : true,
						btnCancelLabel : '取消',
						btnOKLabel : '确定',
						callback : function(result) {
							// 点击确定按钮时，result为true
							if (result) {
								// 执行方法
								var myForm = document.createElement("form");
								myForm.method = "post";
								myForm.action = '/examsys/depository/toKnows';
								var myInput = document.createElement("input");
								myInput.setAttribute("name", "depId");  // 为input对象设置name
								myInput.setAttribute("value", id);  // 为input对象设置value
								myForm.appendChild(myInput);
								document.body.appendChild(myForm);
								myForm.submit();
								document.body.removeChild(myForm);  // 提交后移除创建的form
							}
						}
					});
				}else{
					BootstrapDialog.confirm({
						title : '提示',
						message : data.msg,
						size : BootstrapDialog.SIZE_SMALL,
						type : BootstrapDialog.TYPE_DEFAULT,
						closable : true,
						btnCancelLabel : '取消',
						btnOKLabel : '确定'
					});
				}
			}
		})
	}

</script>
</body>
</html>

